10107
3062
 
特別是兩件事可能需要注意:
全局聲明const RecaptchaItem = React.createClass({..}),不要在render()中使其成為局部變量
必須同時提供onloadCallback和verifyCallback,如果缺少onloadCallback,則reCAPTCHA將不會觸發調用verifyCallback,並且Form無法獲取該值。這可能是react-recaptcha的錯誤
這是正確的代碼:
const {Form,Icon,Input,Button,Checkbox} = antd;
const FormItem = Form.Item;
const RecaptchaItem = React.createClass({
verifyCallback(result){
console.log('verifyCallback',結果);
this.props.onChange(result); //驗證後通知表單
},
render(){
返回( {}}
verifyCallback = {this.verifyCallback}
/>);
}
});
const NormalLoginForm = Form.create()(React.createClass({
handleSubmit(e){
e.preventDefault();
this.props.form.validateFields((err,values)=> {
如果(!err){
console.log('接收的值的形式:',值);
}
});
},
render(){
const {getFieldDecorator} = this.props.form;
返回(
{getFieldDecorator('userName',{ 規則:[{必填:是,消息:“請輸入您的用戶名!” }], })( } placeholder =“ Username” /> )} {getFieldDecorator('password',{ 規則:[{必填:是,消息:“請輸入密碼!” }], })( } type =“ password”佔位符=“ Password” /> )} {getFieldDecorator('captcha',{ 規則:[{必填:是,消息:“請輸入您所獲得的驗證碼!” }], })()} {getFieldDecorator('remember',{ valuePropName:“已選中”, initialValue:true, })( 記住我 )} 忘記密碼